﻿//541.反转字符串II
class Solution {
public:
    string reverseStr(string s, int k) {
        int len = s.size();
        for (int i = 0; i < len; i += 2 * k)
        {
            reverse(s.begin() + i, s.begin() + i + min(k, len - i));
        }
        return s;
    }
};

//557.反转字符串中的单词III
class Solution {
public:
    string reverseWords(string s) {
        size_t prev = 0;
        size_t pos = s.find(' ');
        while (pos != string::npos)
        {
            reverse(s.begin() + prev, s.begin() + pos);
            prev = pos + 1;
            pos = s.find(' ', prev);
        }
        reverse(s.begin() + prev, s.end());

        return s;
    }
};